<template>
  <section class="unit-container">
    <section class="unit-header">
      <section class="unit-state">
        <span class="state">已下单</span>
        <section
          class="description"
        >{{ props.order.order_date }} | {{ $store.getters.getUserInfo.user_name }} | 订单号: {{ props.order.order_no }} | 在线支付 [快捷支付]</section>
      </section>
      <section class="price">
        支付金额：
        <span class="price-num">{{ amount }}</span> 元
      </section>
    </section>
    <section class="unit-body">
      <section class="product-card" v-for="product in props.order.products">
        <n-image :src="product.img" width="50" class="product-img"></n-image>
        <section class="product-info">
          <section class="product-title">{{ product.pro_title }}</section>
          <section class="product-price">169元 × 1</section>
        </section>
      </section>
    </section>
  </section>
</template>
<script setup lang="ts">
import $store from '../../store';
import { computed } from '@vue/reactivity';

const props = defineProps({
  order: {
    type: Object,
    required: true,
  },
});
const amount = computed(() => {
  return props.order.products.reduce((last: any, curr: any) => {
    return last + curr.pro_price * curr.pro_num;
  }, 0) || 0;
});
console.log(props.order);
</script>
<style scoped>
.unit-container {
  border: 1px solid #83c44e;
}

.unit-container + .unit-container {
  border-top: none;
}

.unit-header {
  border-bottom: 1px solid #cfeeab;
  background-color: #fbfff6;
  padding: 20px;
  display: flex;
}

.unit-state {
  display: flex;
  flex-direction: column;
  width: 80%;
}

.state {
  color: #83c44e;
  font-size: 18px;
}

.description {
  color: #3f3f3faa;
}

.price {
  display: flex;
  align-items: flex-end;
}

.price-num {
  display: inline-block;
  font-size: 24px;
  line-height: 28px;
  margin: 0 2px;
}
.unit-body {
  padding: 20px;
}

.product-card {
  display: flex;
  align-items: center;
  padding-top: 20px;
  margin-bottom: 20px;
}

.product-card + .product-card {
  border-top: 1px solid #cfeeab;
}

.product-info {
  margin-left: 20px;
}
</style>